// pages/me/me.js
import {
  PersonModel
} from '../../models/personal.js'
let personModel = new PersonModel()
import {
  AuthModel
} from '../../models/authData.js'
let authModel = new AuthModel()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    personalData: '',
    receivingCount: 0,
    closedCount: 0,
    skillGradeText: '',
    authBtnTitle: '立即认证',
    FGatheringCode: '',
    authenticationStatus: '1',
  },

  pushToOrderList() {
    wx.navigateTo({
      url: '/pages/orderList/orderList',
    })
  },

  pushToAuth () {
    wx.navigateTo({
      url: `/pages/auth/auth?FItEmpId=${this.data.personalData.FId}`,
    })
  },

  pushToPersonInfo() {
    wx.navigateTo({
      url: `/pages/personInfo/personInfo?personalData=${JSON.stringify(this.data.personalData)}`
    })
  },

  pushToEditPersonInfo() {
    wx.navigateTo({
      url: `/pages/editPersonInfo/editPersonInfo?fromPage=me&mobile=${this.data.personalData.FMobile}`,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    wx.setNavigationBarTitle({
      title: '个人中心'
    })
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: '#3B80FE',
      animation: {
        duration: 400,
        timingFunc: 'easeIn'
      }
    })
    wx.showLoading({
      mask: true
    })
    const personal = personModel.getPersonalData()
    const orderInfo = personModel.getOrderData()
    const auth = authModel.getSelfAuthData()
    Promise.all([personal, orderInfo, auth])
      .then(res => {
        let ifAuthentication
        let status
        if (res[2].data.data.resumeData.authenticationInfoList[0]) {
          if (res[2].data.data.resumeData.authenticationInfoList[0].FAuthenticationStatus === 'New' || res[2].data.data.resumeData.authenticationInfoList[0].FAuthenticationStatus === 'Back') {
            ifAuthentication = '立即认证'
          } else {
            if (res[2].data.data.resumeData.authenticationInfoList[0].FAuthenticationStatus === 'Auditing') {
              ifAuthentication = '更新认证'
              status = '2'
            }
            if (res[2].data.data.resumeData.authenticationInfoList[0].FAuthenticationStatus === 'Audited') {
              status = '3'
              ifAuthentication = '更新认证'
            }
          }
        } else {
          status = '1'
          ifAuthentication = '立即认证'
        }
        wx.hideLoading()
        var FSkillGradeText = ''
        var FGatheringCode = ''
        if (res[2].data.data.resumeData.authenticationInfoList[0]) {
          FSkillGradeText = res[2].data.data.resumeData.authenticationInfoList[0].FSkillGradeText
        }

        if (res[2].data.data.resumeData.authenticationInfoList[0]) {
          FGatheringCode = res[2].data.data.resumeData.authenticationInfoList[0].FGatheringCode
        }
        
        this.setData({
          personalData: res[0].data.data.records ? res[0].data.data.records:'',
          closedCount: res[1].data.data.closedCount ? res[1].data.data.closedCount:0,
          receivingCount: res[1].data.data.receivingCount ? res[1].data.data.receivingCount:0,
          skillGradeText: FSkillGradeText ? FSkillGradeText:'',
          FGatheringCode: FGatheringCode,
          authBtnTitle: ifAuthentication ? ifAuthentication:'',
          authenticationStatus: status ? status:'',
        })
      })
  },

  showCode() {
    if (!this.data.FGatheringCode) {
      return
    }
    var url = 'https://www.myhr100.com:4200/Ecp.Picture.view.img?pictureId=' + this.data.FGatheringCode
    var urls = [url]
    wx.previewImage({
      current: url,
      urls: urls,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})